package cate.game.train.equip.msg;

import cate.common.annotation.OperationSetter;
import cate.common.table.d.GDOperation;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBTrain;
import cate.game.role.Role;
import cate.game.role.bag.hero.Hero;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcResult;

import java.util.List;

@ClientMsg(title = "英雄脱装备の 请求")
@OperationSetter(GDOperation.EQUIP_OFF)
public class HeroEquipOffReq implements MsgInput {
    @NoteField(value = "英雄ID", detail = "要给哪一个英雄脱装备")
    public String heroUid;

    @NoteField(value = "要脱掉的部位枚举", detail = "是部位，不是模板ID")
    public List<Byte> posList;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        Role role = cc.getRole();
        HeroEquipOffResp resp = new HeroEquipOffResp();
        resp.heroUid = heroUid;
        Hero hero = role.getBag().hero.getItem(heroUid);
        if(hero == null){
            game.notice.message(cc.getRole(), "英雄不存在");
            return;
        }
        EcResult<Byte> r;
        for (Byte pos : posList) {
            r = hero.offEquip(game.fight.getPlayBuildContext(), pos);
            if (r.ok()) {
                resp.posList.add(r.data);
            } else {
                game.notice.message(cc.getRole(), r, true);
            }
        }
        cc.getRole().getBase().updatePower();
        cc.sendNow(resp);
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBTrain.HERO_EQUIP_OFF_REQ;
    }
}
